#include "stdafx.h"
#include "List.h"

namespace wlog {

	Hashtable^ List::GetFields(void)
	{
		Hashtable^ fields = gcnew Hashtable;
		fields->Add("id_user", Configure::USER_ID);
		fields->Add("name", BaseModel::SafeValue(this->name));
		fields->Add("day_at", this->day_at);

		this->f_req = gcnew ArrayList;
		this->f_req->Add("name");

		this->VerifyFields(fields);

		return fields;
	}

	Hashtable^ List::GetItemByDayAt(String^ day_at)
	{
		Hashtable^ item = this->db->CreateQuery(this->ToString())
								  ->AndWhere("day_at = ", day_at)
								  ->AndWhere("id_user = ", Configure::USER_ID)
								  ->GetRow();
		return item;
	}

	bool List::IsExist(String^ day_at)
	{
		Hashtable^ item = this->GetItemByDayAt(day_at);
		if (item->ContainsKey("name") && !item["name"]->Equals(""))
		{
			return true;
		}
		return false;
	}

	ArrayList^ List::GetAll(void)
	{
		return this->db->CreateQuery(this->ToString())
					   ->AndWhere("id_user = ", Configure::USER_ID)
					   ->Order("day_at")
					   ->GetAll();
	}


}